﻿package {
	/* relevant imports that are required */
	import com.fecesaids.greatgame.Communication;
	import flash.events.*
	import flash.utils.Timer;
	import flash.display.MovieClip;
	
	public class Game2Main extends MovieClip{
		public var com:Communication = new Communication();
		public function Game2Main() {
			// Delay the initialization until the container has set up listeners:
			var timer = new Timer(100, 1);
			timer.addEventListener("timer", init); 
			timer.start();
			sweetButton.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
		}
		public function mouseDownHandler(mEvent:MouseEvent):void{
			if(mEvent.target.name == "sweetButton")
				com.loadGame(["game3.swf", "houseDoor", "blackGuyBrainDoor"]);
		}
		public function receiveGameData(lastGameName:String, lastGameExit:String, thisGameEntrance:String){
			trace("Last game name: " + lastGameName);
			trace("Last game exit: " + lastGameExit);
			trace("This game entrance: " + thisGameEntrance);
		}
		private function init(evt:TimerEvent) {
			/* This function acts as the constructor so the beginning can be delayed by enough time to create
				the relevant listeners in the container */
			com.modHealth(-10); // This modifies the player's current health by some amount
			com.modName("Michael Jackson's Moonwalker"); // This changes the player's name
			
			/* The following line changes the player's avatar picture on the HUD, in order to change the avatar
				you must have an image in the fla's library and it's properties must be set up like so...
				First of all, you must make the image (a png for example) a movieclip by putting it on the stage
				and going to modify > convert to symbol and select movieclip. Check the box for "export for actionscript"
				and then set the Class to something such as "mj_avatar" and leave the base class as "flash.display.MovieClip"
			*/
			com.modAvatar(new mj_avatar());
			
			/* The following line allows you to add an item into the player's inventory based on an existing movieclip
				in the library. First of all, you must set up the inventory item's movieclip in the same way you would
				set up an avatar picture by checking "export for actionscript" and giving it a class name. 
				com.addInvItem accepts 4 parameters, the name of the item, the base item type, an instance of the movieclip
				the inventory item should use, and an array that defines the actions that the item can perform.
				The structure of the action array is as follows:
				[["Name of the action (for the item's context menu)", "Action type", <relevant additional values>],["Drink", "Heal", 10]]
			*/
			com.addInvItem(["Michael's White Glove", "Glove", new mjGlove(), [["Touch Chillen", "heal", 10], ["Cancel"]]]);
			com.addInvItem(["Michael's White Glove", "Glove", new mjGlove(), [["Touch Chillen", "heal", 10], ["Cancel"]]]);
			com.remInvItem(["Glove", 1]); // Removes one item of base type "Glove"
			
			if(com.hasItem(["Glove", 1])){ // Checks to see if the player has some amount of an item with the relevant base item type
				trace("You have the item!"); // You have the item
			}
			else{
				trace("Ain't got shit"); // You do not have the item
			}
		}
	}
}